<template>
  <div>
    <!-- 页面顶部面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/Home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 内容显示面板 -->
    <el-card class="box-card">
      <el-table :data="rightslist" border stripe :cell-style="columnclass" :header-cell-style="headercell">
        <el-table-column type="index" label="序号" width="50px" />
        <el-table-column label="权限名称" prop="authName" />
        <el-table-column label="路径" prop="path" />
        <el-table-column label="权限等级" prop="level">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level==='1'">一级</el-tag>
            <el-tag v-else-if="scope.row.level==='2'" type="success">二级</el-tag>
            <el-tag v-else type="warning">三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination :current-page="1" :page-sizes="[ 10, 20, 30]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      rightslist: [],
      total: 2
    }
  },
  created() {
    this.getrightslist()
  },
  methods: {
    // 表格样式回调函数
    headercell({ row, rowIndex }) {
      return 'text-align:center'
    },
    columnclass({ row, column, rowIndex, columnIndex }) {
      return 'text-align:center'
    },
    // 请求权限列表
    async getrightslist() {
      const { data: res } = await this.$http.get('rights/list')
      if (res.meta.status !== 200) {
        return this.$message.error(res.meta.msg)
      }
      this.rightslist = res.data
      console.log(this.rightslist)
      return this.$message.success(res.meta.msg)
    },
    // 当前显示数据条数发生改变重置参数对应值并刷新用户列表
    handleSizeChange(val) {
      this.queryinfor.pagesize = val
      this.getrightslist()
    },
    // 当前显示页码发生改变重置参数对应值并刷新用户列表
    handleCurrentChange(val) {
      this.queryinfor.pagenum = val
      this.getrightslist()
    }
  }
}
</script>
<style lang="scss" scoped>
.box-card {
  margin-top: 20px;
}
.el-pagination {
  text-align: right;
  margin-top: 20px;
}
</style>
